www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/MoneyPay.cpp

    //Download by http://www.NewXing.com
// MoneyPay.cpp : implementation file
//

#include "stdafx.h"
#include "qq.h"
#include "MoneyPay.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <winuser.h>
/////////////////////////////////////////////////////////////////////////////
// CMoneyPay dialog


CMoneyPay::CMoneyPay(CWnd* pParent /*=NULL*/)
	: CDialog(CMoneyPay::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMoneyPay)
	m_nMoneyType = 1;
	//}}AFX_DATA_INIT
	bMoneyInSQL=false;
}


void CMoneyPay::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMoneyPay)
	DDX_Control(pDX, IDC_SUBMONEY, SubMoney);
	DDX_Control(pDX, IDC_PAYSUMMONEY, Sum);
	DDX_Control(pDX, IDC_PAIDNUMMONEY, Paid);
	DDX_Control(pDX, IDC_BILLCODEPAYMONEY, BillCode);
	DDX_Radio(pDX, IDC_RADIO1, m_nMoneyType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMoneyPay, CDialog)
	//{{AFX_MSG_MAP(CMoneyPay)
	ON_EN_CHANGE(IDC_BILLCODEPAYMONEY, OnBillcodeChange)
	ON_EN_CHANGE(IDC_PAIDNUMMONEY, OnChangePaidmoney)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMoneyPay message handlers

BOOL CMoneyPay::OnInitDialog() 
{
	CDialog::OnInitDialog();

	HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
	this->SetIcon(m_hIcon,true);//设置对话框图标
	// TODO: Add extra initialization here
	Sum.SetWindowText("0");
	Paid.SetWindowText("0");
	SubMoney.SetWindowText("0");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMoneyPay::OnBillcodeChange() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	//当输入帐单号码时自动填写要付的总数以及计算余额
	//当输入完帐单号码时进行计算
    CString strBillCode="";
	BillCode.GetWindowText(strBillCode);//获得帐单文本
	if(!m_BillInfoSet.Open())
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return;
	}
	bool bhas=false;
	m_BillInfoSet.MoveFirst();//移动到第一条记录
	while (!m_BillInfoSet.IsEOF())
	{
        if(m_BillInfoSet.m_BillCode==strBillCode)
		{//在数据库中找到要付款的帐单号
			bhas=true;
            long nShouldMoney=0;
			nShouldMoney=m_BillInfoSet.m_Sum-m_BillInfoSet.m_Paid;
			if(nShouldMoney<=0)
			{
				MessageBox("你已经支付了这个帐单!","付款错误",MB_OK);
				BillCode.SetWindowText("");
				break;
			}
			else
			{
				CString strMoney;
                strMoney.Format("%ld",nShouldMoney);
                Sum.SetWindowText(strMoney);
				break;
			}
		}
		m_BillInfoSet.MoveNext();//移动到下一条记录
	}

		m_BillInfoSet.Close();//关闭数据库
		if(!bhas)
		{
			Sum.SetWindowText("0");
			return;
		}
	
}

void CMoneyPay::OnChangePaidmoney() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strPaidMoney="",strSumMoney="";
    Paid.GetWindowText(strPaidMoney);//得到当前的输入文本
    Sum.GetWindowText(strSumMoney);  //得到当前要支付的总数
	char* sPaid=strPaidMoney.GetBuffer(strPaidMoney.GetLength());
	char* sSum=strSumMoney.GetBuffer(strSumMoney.GetLength());
	long nSubMoney=0,nPaidMoney=0,nSumMoney=0;
	nPaidMoney=atol(sPaid);
	nSumMoney=atol(sSum);
	nSubMoney=nPaidMoney-nSumMoney;
	CString strSubMoney;
	strSubMoney.Format("%ld",nSubMoney);
	SubMoney.SetWindowText(strSubMoney);//计算剩余的钱
}

void CMoneyPay::OnOK() 
{
	// TODO: Add extra validation here
	//保存记录到数据库中
	CString strBillCode;
	BillCode.GetWindowText(strBillCode);//得到当前的帐单号码
	CString strSubMoney;
	SubMoney.GetWindowText(strSubMoney);
	char* s=strSubMoney.GetBuffer(strSubMoney.GetLength());
	long nmoney=atol(s);
	if(!bMoneyInSQL)
	{//如果不将剩下的钱存入到酒店中

		if(nmoney>=0)
		{
			CString SQLstr;
			SQLstr="select * from BillInfo where BillCode='";
			SQLstr=SQLstr+strBillCode;
			SQLstr=SQLstr+"'";
			if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_BillInfoSet.Edit();//编辑数据库
            m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum;
			m_BillInfoSet.m_Striked=true;
			m_BillInfoSet.Update();//更新
			m_BillInfoSet.Close();//关闭数据库
		}
		else
		{
			CString SQLstr;
			SQLstr="select * from BillInfo where BillCode='";
			SQLstr=SQLstr+strBillCode;
			SQLstr=SQLstr+"'";
			if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
			{
				MessageBox("打开数据库失败!","数据库错误",MB_OK);
				return;
			}
			m_BillInfoSet.Edit();//编辑数据库
            m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum+nmoney;
			m_BillInfoSet.m_Striked=true;
			m_BillInfoSet.Update();//更新
			m_BillInfoSet.Close();//关闭数据库
		}
	}
	else
	{
        CString SQLstr;
		SQLstr="select * from BillInfo where BillCode='";
		SQLstr=SQLstr+strBillCode;
		SQLstr=SQLstr+"'";
		if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
		{
			MessageBox("打开数据库失败!","数据库错误",MB_OK);
			return;
		}
		m_BillInfoSet.Edit();//编辑数据库
		m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum+nmoney;
		m_BillInfoSet.m_Striked=true;
		m_BillInfoSet.Update();//更新
		m_BillInfoSet.Close();//关闭数据库
	}
	CDialog::OnOK();
}

void CMoneyPay::OnRadio() 
{
	// TODO: Add your control notification handler code here
	this->UpdateData(true);//更新数据
	CString strSubMoney;
	SubMoney.GetWindowText(strSubMoney);
	char* s=strSubMoney.GetBuffer(strSubMoney.GetLength());
	bool bBigZero=false;
	long nmoney=atol(s);//得到余额的情况
	if(nmoney>=0)
	{
		bBigZero=true;
	}
	else
	{
		bBigZero=false;
	}
	if(m_nMoneyType==0)
	{//选择的是"是"
		if(bBigZero)
		{
			bMoneyInSQL=true;
		}
		else
		{
			bMoneyInSQL=false;
            MessageBox("对不起,你没有足够的钱存入酒店!","存入错误",MB_OK);
		}
	}
	if(m_nMoneyType==1)
	{
		bMoneyInSQL=false;
	}
}

void CMoneyPay::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
}

int CMoneyPay::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
//	AnimateWindow(GetSafeHwnd(),1000,AW_CENTER);
	return 0;
}